package com.biodiv.transport.factory;


import com.biodiv.miracle.ioc.context.ApplicationContext;
import com.biodiv.miracle.ioc.factory.FactoryBean;

import java.lang.reflect.Proxy;

/**
 * @author: tianquan
 * @date: 2025-05-30  10:05
 * @description: 生成代理类的类
 */
public class TransportFactoryBean<T> implements FactoryBean<T> {

    private final Class<T> transportClient;
     private final ApplicationContext applicationContext;

    public TransportFactoryBean(Class<T> transportClient, ApplicationContext applicationContext) {
        this.transportClient = transportClient;
        this.applicationContext = applicationContext;
    }

    @Override
    public T getObject() {
        return (T) Proxy.newProxyInstance(
                transportClient.getClassLoader(),
                new Class[]{transportClient},
                new TransportProxy(transportClient, applicationContext));
    }

    @Override
    public Class<?> getObjectType() {
        return transportClient;
    }

}
